function n(n) {
  t(uni.request, n);
}

function t(n, t) {
  var e = t.success,
      i = t.fail,
      r = !1,
      o = null;
  t.success = function (n) {
    r || (o && clearTimeout(o), "function" == typeof e && e(n));
  }, t.fail = function () {
    r || (o && clearTimeout(o), "function" == typeof i && i());
  }, n(t), o = setTimeout(function () {
    o && clearTimeout(o), r = !0, "function" == typeof i && i(r);
  }, t.timeout || U);
}

function e(t) {
  try {
    C.getNetworkInfo(function (e) {
      "NOTREACHABLE" === e.networkType || "none" === e.networkType || !1 === e.networkAvailable ? (O().e("请求失败:暂无网络 "), t.fail()) : n(t);
    }, t.fail);
  } catch (n) {
    O().e("请求失败: " + n);
  }
}

function i(n, t) {
  this.id = n, this.ts = Date.now();
  var e = void 0 === t ? "undefined" : N(t);
  if ("string" === e && t) this[n] = t;else if ("object" === e) for (var i in t) ({}).hasOwnProperty.call(t, i) && (this[i] = t[i]);
}

function r(n) {
  var t = null;

  switch (n) {
    case pn.HALF_SESSION:
      t = o();
      break;

    case pn.CLOSE_SESSION:
      t = c();
      break;

    case pn.EKV:
      t = s();
  }

  return t;
}

function o() {
  var n = null,
      t = hn().cloneCurrentSession();
  return t && (n = {
    header: {
      st: "1"
    },
    analytics: {
      sessions: [t]
    }
  }), n;
}

function c() {
  var n = null,
      t = {},
      e = hn().cloneCurrentSession();

  if (e) {
    var i = b().get(),
        r = nn().get();
    Array.isArray(i) && i.length && (e.pages = W.clone(i)), Array.isArray(r) && r.length && (e.shares = W.clone(r)), b().clear(), nn().clear(), t.sessions = [e];
  }

  var o = on().getEkvs();
  return o && (t.ekvs = W.clone(o), on().clear()), (t.sessions || t.ekvs) && (n = {
    analytics: t
  }), n;
}

function s() {
  var n = null,
      t = on().getEkvs();
  return t && (n = {
    analytics: {
      ekvs: W.clone(t)
    }
  }, on().clear()), n;
}

function u(n) {
  return {
    h: a(n.header, vn),
    a: l(n.analytics, gn)
  };
}

function a(n, t) {
  var e = f(n, t);
  return n.id_tracking && (e[t.id_tracking || "id_tracking"] = f(n.id_tracking, _n)), e;
}

function f(n, t) {
  var e = {};

  for (var i in n) t[i] ? e[t[i]] = n[i] : e[i] = n[i];

  return e;
}

function l(n, t) {
  var e = {};

  if (n) {
    var i = n.ekvs,
        r = n.sessions;
    i && (e[t.ekvs] = i), Array.isArray(r) && (e[t.sessions] = r);
  }

  return e;
}

function d(n, t, i, r) {
  dn.instance().setIdType(Z().getIdType()), dn.instance().setIdTracking(Z().getIdTracking());
  var o = W.clone(dn.instance().get());
  n.header = Object.assign(o, n.header, {
    ts: Date.now()
  });
  var c = u(n),
      s = w.stringify(c),
      a = {
    url: D.LOG_URL,
    method: "POST",
    data: W.base64Encode(s),
    success: function (n) {
      var e = n.code || n.status || n.statusCode;
      200 === e || 413 === e ? (O().i("数据发送成功: ", s), p((n.data || {}).imprint), "function" == typeof t && t(n)) : (O().w("数据发送失败: ", s), "function" == typeof i && i());
    },
    fail: function (n) {
      O().w("超时: ", s), "function" == typeof i && i();
    },
    complete: function () {
      "function" == typeof r && r();
    }
  };
  e(Object.assign(a, h()));
}

function p(n) {
  if (n) {
    L().set(D.IMPRINT, n), dn.instance().setItem(D.IMPRINT, n);
    var t = w.parse(W.base64Decode(n));
    O().v("imprint: %o", t);
    var e = t.report_policy;

    if (e && W.isNumber(e) && (L().set(D.REPORT_POLICY, e), e === D.REPORT_POLICY_INTERVAL)) {
      var i = t.report_interval;
      i && W.isNumber(i) && (i <= D.EVENT_SEND_MIN_INTERVAL ? i = D.EVENT_SEND_MIN_INTERVAL : i > D.EVENT_SEND_MAX_INTERVAL && (i = D.EVENT_SEND_MAX_INTERVAL), L().set(D.REPORT_INTERVAL_TIME, i));
    }
  }
}

function h() {
  return {
    header: {
      "Content-Type": "wxmp/json",
      "Msg-Type": "wxmp/json"
    }
  };
}

function g(n) {
  var t = n,
      e = [];
  this.enqueue = function (n) {
    "number" == typeof t && this.size() >= t && this.dequeue(), e.push(n);
  }, this.dequeue = function () {
    return e.shift();
  }, this.front = function () {
    return e[0];
  }, this.isEmpty = function () {
    return 0 === e.length;
  }, this.clear = function () {
    e.length = 0;
  }, this.size = function () {
    return e.length;
  }, this.items = function () {
    return e;
  }, this.print = function () {
    console.log(e.toString());
  };
}

function v() {
  function n() {
    Z().init(function () {
      dn.instance().init(), O().v("Header初始化成功");
    });
  }

  function t(n) {
    var t = !1,
        e = L().get(D.REPORT_POLICY);

    if (e && e === D.REPORT_POLICY_INTERVAL) {
      var i = L().get(D.REPORT_INTERVAL_TIME),
          r = L().get(D.EVENT_LAST_SEND_TIME);
      t = !r, i = i || D.EVENT_SEND_MIN_INTERVAL;
      var o = n - r;
      t = t || o > 1e3 * i;
    }

    return t;
  }

  function e(n) {
    L().set(D.EVENT_LAST_SEND_TIME, n);
  }

  function r(n, t) {
    if (!n || "string" != typeof n) return O().e('please check trackEvent id. id should be "string" and not null'), !1;
    if (n.length > D.MAX_EVENTID_LENGTH) return O().e("The maximum length of event id shall not exceed " + D.MAX_EVENTID_LENGTH), !1;
    if (t && ("object" != (void 0 === t ? "undefined" : N(t)) || Array.isArray(t)) && "string" != typeof t) return O().e("please check trackEvent properties. properties should be string or object(not include Array)"), !1;

    if ("object" == (void 0 === t ? "undefined" : N(t))) {
      var e = 0;

      for (var i in t) if ({}.hasOwnProperty.call(t, i)) {
        if (i.length > D.MAX_PROPERTY_KEY_LENGTH) return O().e("The maximum length of property key shall not exceed " + D.MAX_PROPERTY_KEY_LENGTH), !1;
        if (e >= D.MAX_PROPERTY_KEYS_COUNT) return O().e("The maximum count of properties shall not exceed " + D.MAX_PROPERTY_KEYS_COUNT), !1;
        e += 1;
      }
    }

    return !0;
  }

  var o = !1,
      c = !1;
  this.init = function (t) {
    O().v("sdk version: " + D.IMPL_VERSION), o ? O().v("Lib重复实例化") : L().load(function () {
      O().v("cache初始化成功: ", L().getAll()), n(), o = !0, "function" == typeof t && t(), O().tip("SDK集成成功");
    });
  }, this.resume = function (n) {
    if (o && !c) {
      O().v("showOptions: ", n), c = !0, yn().load();
      var t = hn().resume(n),
          e = hn().getCurrentSessionId();

      if (on().setSessionId(e), t) {
        var i = this;
        yn().add(pn.HALF_SESSION, function () {
          k().useOpenid() && k().autoGetOpenid() && !Z().getId() ? Z().getOpenIdAsync({
            success: function (n) {
              O().v("获取openid成功: %s", n), i.setOpenid(n);
            },
            fail: function () {
              O().v("获取openid失败");
            }
          }) : yn().send();
        });
      }
    }
  }, this.pause = function () {
    o && (c = !1, hn().pause(), yn().send(pn.CLOSE_SESSION, function () {
      yn().save(), L().save(), O().v("cache save success");
    }));
  }, this.setOpenid = function (n) {
    Z().getId() || (O().v("setOpenId: %s", n), Z().setOpenid(n), yn().send());
  }, this.setUnionid = function (n) {
    O().v("setUnionid: %s", n), Z().setUnionid(n);
  }, this.setUserid = function (n) {
    O().v("setUserid: %s", n), Z().setUserid(n);
  }, this.trackEvent = function (n, c) {
    if (o && (O().v("event: ", n, c), r(n, c))) {
      var s = new i(n, c);
      on().addEvent(s);
      var u = Date.now();
      t(u) && (e(u), yn().send(pn.EKV, function () {}));
    }
  }, this.trackShare = function (n) {
    if (o) {
      try {
        n = nn().add(n), O().v("sharePath: ", n.path);
      } catch (n) {
        O().v("shareAppMessage: ", n);
      }

      return n;
    }
  }, this.trackPageStart = function (n) {
    o && b().addPageStart(n);
  }, this.trackPageEnd = function (n) {
    o && b().addPageEnd(n);
  };
}

function _() {}

function y(n, t, e) {
  var i = n[t];

  n[t] = function (n) {
    e.call(this, n), i && i.call(this, n);
  };
}

function E(n) {
  try {
    Nn.init(n);
  } catch (n) {
    O().v("onAppLaunch: ", n);
  }
}

function S(n) {
  try {
    Nn.resume(n);
  } catch (n) {
    O().v("onAppShow: ", n);
  }
}

function m() {
  try {
    Nn.pause();
  } catch (n) {
    O().v("onAppHide: ", n);
  }
}

function I() {
  try {
    Nn.trackPageStart(this.route);
  } catch (n) {
    O().v("onPageShow: ", n);
  }
}

function A() {
  try {
    Nn.trackPageEnd(this.route);
  } catch (n) {
    O().v("onPageHide: ", n);
  }
}

var N = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (n) {
  return typeof n;
} : function (n) {
  return n && "function" == typeof Symbol && n.constructor === Symbol && n !== Symbol.prototype ? "symbol" : typeof n;
},
    T = "[UMENG] -- ",
    O = function () {
  function n() {
    this.setDebug = function (n) {
      e = n;
    }, this.d = function () {
      if (e) try {
        "string" == typeof arguments[0] && (arguments[0] = T + arguments[0]), console.debug.apply(console, arguments);
      } catch (n) {}
    }, this.i = function () {
      try {
        if (e) try {
          "string" == typeof arguments[0] && (arguments[0] = T + arguments[0]), console.info.apply(console, arguments);
        } catch (n) {}
      } catch (n) {}
    }, this.e = function () {
      if (e) try {
        "string" == typeof arguments[0] && (arguments[0] = T + arguments[0]), console.error.apply(console, arguments);
      } catch (n) {}
    }, this.w = function () {
      if (e) try {
        "string" == typeof arguments[0] && (arguments[0] = T + arguments[0]), console.warn.apply(console, arguments);
      } catch (n) {}
    }, this.v = function () {
      if (e) try {
        "string" == typeof arguments[0] && (arguments[0] = T + arguments[0]), console.log.apply(console, arguments);
      } catch (n) {}
    }, this.t = function () {
      if (e) try {
        console.table.apply(console, arguments);
      } catch (n) {}
    }, this.tip = function () {
      try {
        "string" == typeof arguments[0] && (arguments[0] = T + arguments[0]), console.log.apply(console, arguments);
      } catch (n) {}
    }, this.tip_w = function () {
      try {
        "string" == typeof arguments[0] && (arguments[0] = T + arguments[0]), console.warn.apply(console, arguments);
      } catch (n) {}
    }, this.err = function () {
      try {
        "string" == typeof arguments[0] && (arguments[0] = T + arguments[0]), console.error.apply(console, arguments);
      } catch (n) {}
    };
  }

  var t = null,
      e = !1;
  return function () {
    return null === t && (t = new n()), t;
  };
}(),
    R = {
  set: function (n, t, e) {
    var i,
        r = {
      key: n,
      success: function (n) {
        "function" == typeof e && e(n);
      },
      fail: function () {
        "function" == typeof e && e();
      }
    };
    r.data = t, i = uni.setStorage;

    try {
      i && i(r);
    } catch (n) {
      O.e("存储错误", n);
    }
  },
  get: function (n, t) {
    var e;
    e = uni.getStorage;

    try {
      e && e({
        key: n,
        success: function (n) {
          "function" == typeof t && t(n.data);
        },
        fail: function (e) {
          O().w(n + ": " + e.errMsg), "function" == typeof t && t();
        }
      });
    } catch (n) {
      O.e("获取storage错误", n);
    }
  },
  remove: function (n, t) {
    var e;
    e = uni.removeStorage;

    try {
      e && e({
        key: n,
        success: function () {
          "function" == typeof t && t(!0);
        },
        fail: function () {
          "function" == typeof t && t(!1);
        }
      });
    } catch (n) {
      O.e("删除storage错误", n);
    }
  }
},
    w = {
  stringify: function (n) {
    if (n) try {
      return JSON.stringify(n);
    } catch (n) {}
    return "";
  },
  parse: function (n) {
    if (n) try {
      return JSON.parse(n);
    } catch (n) {}
    return null;
  },
  parseToArray: function (n) {
    if (n) try {
      return JSON.parse(n);
    } catch (n) {}
    return [];
  }
},
    k = function () {
  function n() {
    var n = {};
    this.useOpenid = function () {
      return n.useOpenid;
    }, this.autoGetOpenid = function () {
      return n.autoGetOpenid;
    }, this.appKey = function () {
      return n.appKey;
    }, this.set = function (t) {
      n = t;
    }, this.get = function () {
      return n;
    }, this.setItem = function (t, e) {
      n[t] = e;
    }, this.getItem = function (t) {
      return n[t];
    };
  }

  var t = null;
  return function () {
    return t || (t = new n()), t;
  };
}(),
    L = function () {
  function n() {
    this.load = function (n) {
      i ? (R.remove(e), n()) : (e = "um_cache_" + k().appKey(), R.get(e, function (t) {
        i = w.parse(t) || {}, r = !0, R.remove(e), n();
      }));
    }, this.save = function () {
      i && R.set(e, w.stringify(i));
    }, this.set = function (n, t) {
      i && (i[n] = t);
    }, this.get = function (n) {
      return (i || {})[n];
    }, this.remove = function (n) {
      i && i[n] && delete i[n];
    }, this.getAll = function () {
      return i;
    }, this.clear = function () {
      i = null;
    }, this.has = function (n) {
      return !!this.get(n);
    }, this.isLoaded = function () {
      return r;
    };
  }

  var t = null,
      e = "",
      i = null,
      r = !1;
  return function (e) {
    return t || (t = new n(e)), t;
  };
}(),
    P = "",
    D = {
  SESSION_INTERVAL: 3e4,
  LOG_URL: P = "https://ulogs.umeng.com/wxm_logs",
  GET_OPENID_URL: "https://ulogs.umeng.com/uminiprogram_logs/wx/getuut",
  DEVICE_INFO_KEY: "device_info",
  ADVERTISING_ID: "mobile_ad_id",
  ANDROID_ID: "android_id",
  CURRENT_SESSION: "current_session",
  SESSION_PAUSE_TIME: "session_pause_time",
  EVENT_SEND_MIN_INTERVAL: 5,
  EVENT_SEND_MAX_INTERVAL: 86400,
  EVENT_LAST_SEND_TIME: "last_send_time",
  MAX_EVENTID_LENGTH: 128,
  MAX_PROPERTY_KEY_LENGTH: 256,
  MAX_PROPERTY_KEYS_COUNT: 100,
  REPORT_POLICY: "report_policy",
  REPORT_INTERVAL_TIME: "report_interval_time",
  REPORT_POLICY_START_SEND: "1",
  REPORT_POLICY_INTERVAL: "6",
  IMPRINT: "imprint",
  SEED_VERSION: "1.0.0",
  IMPL_VERSION: "2.2.3",
  ALIPAY_AVAILABLE_VERSION: "10.1.52",
  SHARE_PATH: "um_share_path",
  SHARES: "shares",
  REQUESTS: "requests",
  UUID: "um_uuid",
  UUID_SUFFIX: "ud",
  OPENID: "um_od",
  UNIONID: "um_unid",
  ALIPAYID: "um_alipayid",
  USERID: "um_userid",
  LAUNCH_OPTIONS: "LAUNCH_OPTIONS",
  UM_SSRC: "_um_ssrc",
  IS_ALIYUN: !1,
  ALIYUN_URL: "serverless.huoban.youmeng.network.forward"
},
    C = {
  getUserInfo: function (n) {
    uni.getSetting({
      success: function (t) {
        t.authSetting["scope.userInfo"] ? uni.getUserInfo({
          success: function (t) {
            n(t && t.userInfo);
          },
          fail: function () {
            n({});
          }
        }) : n({});
      },
      fail: function () {
        n({});
      }
    });
  },
  getSystemInfo: function (n, t) {
    uni.getSystemInfo({
      success: function (t) {
        "function" == typeof n && n(t);
      },
      fail: function () {
        "function" == typeof t && t();
      }
    });
  },
  getDeviceInfo: function (n) {
    "function" == typeof n && n();
  },
  checkNetworkAvailable: function (n) {
    var t = {
      success: function (t) {
        var e = !1;
        e = "none" !== t.networkType, "function" == typeof n && n(e);
      },
      fail: function () {
        "function" == typeof n && n();
      }
    };
    uni.getNetworkType(t);
  },
  getNetworkInfo: function (n, t) {
    var e = {
      success: function (t) {
        "function" == typeof n && n(t);
      },
      fail: function () {
        "function" == typeof t && t();
      }
    };
    uni.getNetworkType(e);
  },
  getDeviceId: function (n, t) {
    try {
      "function" == typeof n && n("");
    } catch (n) {
      O().e("getDeviceId error", n);
    }
  },
  getAdvertisingId: function (n, t) {
    "function" == typeof n && n("");
  },
  getPageName: function () {},
  onNetworkStatusChange: function (n) {
    uni.onNetworkStatusChange(function (t) {
      "function" == typeof n && n(t.isConnected || !0);
    });
  }
},
    b = function () {
  function n() {
    var n = !1,
        t = null,
        e = [];
    this.addPageStart = function (e) {
      e && !n && (t = {
        ts: Date.now(),
        path: e
      }, n = !0);
    }, this.addPageEnd = function (i) {
      if (n && i && t && i === t.path) {
        var r = Date.now() - t.ts;
        t.duration = Math.abs(r), e.push(t), t = null, n = !1;
      }
    }, this.get = function () {
      return e;
    }, this.clear = function () {
      e.length = 0;
    };
  }

  var t = null;
  return function () {
    return t || (t = new n()), t;
  };
}(),
    U = 5e3,
    M = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
    V = function (n) {
  for (var t = {}, e = 0, i = n.length; e < i; e++) t[n.charAt(e)] = e;

  return t;
}(M),
    x = String.fromCharCode,
    H = function (n) {
  if (n.length < 2) return (t = n.charCodeAt(0)) < 128 ? n : t < 2048 ? x(192 | t >>> 6) + x(128 | 63 & t) : x(224 | t >>> 12 & 15) + x(128 | t >>> 6 & 63) + x(128 | 63 & t);
  var t = 65536 + 1024 * (n.charCodeAt(0) - 55296) + (n.charCodeAt(1) - 56320);
  return x(240 | t >>> 18 & 7) + x(128 | t >>> 12 & 63) + x(128 | t >>> 6 & 63) + x(128 | 63 & t);
},
    Y = function (n) {
  return n.replace(/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g, H);
},
    G = function (n) {
  var t = [0, 2, 1][n.length % 3],
      e = n.charCodeAt(0) << 16 | (n.length > 1 ? n.charCodeAt(1) : 0) << 8 | (n.length > 2 ? n.charCodeAt(2) : 0);
  return [M.charAt(e >>> 18), M.charAt(e >>> 12 & 63), t >= 2 ? "=" : M.charAt(e >>> 6 & 63), t >= 1 ? "=" : M.charAt(63 & e)].join("");
},
    K = function (n) {
  return n.replace(/[\s\S]{1,3}/g, G);
},
    F = function (n) {
  return K(Y(n));
},
    j = new RegExp(["[À-ß][-¿]", "[à-ï][-¿]{2}", "[ð-÷][-¿]{3}"].join("|"), "g"),
    X = function (n) {
  switch (n.length) {
    case 4:
      var t = ((7 & n.charCodeAt(0)) << 18 | (63 & n.charCodeAt(1)) << 12 | (63 & n.charCodeAt(2)) << 6 | 63 & n.charCodeAt(3)) - 65536;
      return x(55296 + (t >>> 10)) + x(56320 + (1023 & t));

    case 3:
      return x((15 & n.charCodeAt(0)) << 12 | (63 & n.charCodeAt(1)) << 6 | 63 & n.charCodeAt(2));

    default:
      return x((31 & n.charCodeAt(0)) << 6 | 63 & n.charCodeAt(1));
  }
},
    q = function (n) {
  return n.replace(j, X);
},
    z = function (n) {
  var t = n.length,
      e = t % 4,
      i = (t > 0 ? V[n.charAt(0)] << 18 : 0) | (t > 1 ? V[n.charAt(1)] << 12 : 0) | (t > 2 ? V[n.charAt(2)] << 6 : 0) | (t > 3 ? V[n.charAt(3)] : 0),
      r = [x(i >>> 16), x(i >>> 8 & 255), x(255 & i)];
  return r.length -= [0, 0, 2, 1][e], r.join("");
},
    J = function (n) {
  return n.replace(/[\s\S]{1,4}/g, z);
},
    Q = function (n) {
  return q(J(n));
},
    B = {
  encode: function (n, t) {
    return t ? F(String(n)).replace(/[+\/]/g, function (n) {
      return "+" == n ? "-" : "_";
    }).replace(/=/g, "") : F(String(n));
  },
  decode: function (n) {
    return Q(String(n).replace(/[-_]/g, function (n) {
      return "-" == n ? "+" : "/";
    }).replace(/[^A-Za-z0-9\+\/]/g, ""));
  }
},
    W = {
  base64Encode: function (n) {
    return B.encode(n, !1);
  },
  base64Decode: function (n) {
    return B.decode(n);
  },
  isNumber: function (n) {
    return !Number.isNaN(parseInt(n, 10));
  },
  compareVersion: function (n, t) {
    for (var e = String(n).split("."), i = String(t).split("."), r = 0; r < Math.max(e.length, i.length); r++) {
      var o = parseInt(e[r] || 0, 10),
          c = parseInt(i[r] || 0, 10);
      if (o > c) return 1;
      if (o < c) return -1;
    }

    return 0;
  },
  getRandomStr: function (n) {
    for (var t = "", e = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"], i = 0; i < Number(n); i++) t += e[Math.round(Math.random() * (e.length - 1))];

    return t;
  },
  clone: function (n) {
    return JSON.parse(JSON.stringify(n));
  }
},
    Z = function () {
  function n() {
    function n() {
      return W.getRandomStr(10) + Date.now() + W.getRandomStr(7) + D.UUID_SUFFIX;
    }

    var t = "",
        i = "",
        r = "",
        o = "",
        c = "";
    this.init = function (e) {
      c = k().useOpenid() ? "openid" : "uuid", R.get(D.UUID, function (r) {
        r ? t = r : (t = n(), R.set(D.UUID, t)), k.useOpenid ? R.get(D.OPENID, function (n) {
          i = n, e && e();
        }) : e && e();
      });
    }, this.getOpenIdAsync = function (n) {
      uni.login({
        success: function (t) {
          t.code ? e({
            url: D.GET_OPENID_URL,
            method: "GET",
            data: {
              key: k().appKey(),
              code: t.code
            },
            success: function (t) {
              if (t && 200 === t.statusCode && t.data && t.data.data) {
                var e = t.data.data;
                return n.success && n.success(e.oid, e.uid);
              }

              n.fail && n.fail();
            },
            fail: function () {
              n.fail && n.fail();
            }
          }) : n.fail && n.fail();
        },
        fail: function () {
          n.fail && n.fail();
        }
      });
    }, this.getIdType = function () {
      return c;
    }, this.getIdTracking = function () {
      var n = {};
      return t && (n.uuid = t), i && (n.openid = i), r && (n.unionid = r), o && (n.userid = o), n;
    }, this.setOpenid = function (n) {
      !i && n && (i = n, R.set(D.OPENID, n));
    }, this.setUnionid = function (n) {
      !r && n && (r = n, R.set(D.UNIONID, n));
    }, this.setUserid = function (n) {
      !o && n && (o = n, R.set(D.USERID, n));
    }, this.getId = function () {
      return k().useOpenid() ? i : t;
    };
  }

  var t = null;
  return function () {
    return t || (t = new n()), t;
  };
}(),
    $ = 3,
    nn = function () {
  function n() {
    return {
      add: function (n) {
        O().v("share origin: %o", n);
        var t = {
          title: n.title,
          path: n.path.split("?")[0],
          _um_sts: Date.now()
        },
            r = n.path,
            o = Z().getId();

        if (o) {
          var c = i.split(","),
              s = (c = c.filter(function (n) {
            return n.length > 0;
          })).indexOf(o);
          s >= 0 && (c = c.slice(0, s)), c.length < $ && c.push(o);
          var u = c.join(",");
          -1 !== r.indexOf("?") ? r += "&_um_ssrc=" + u : r += "?_um_ssrc=" + u;
          var a = Date.now();
          r += "&_um_sts=" + a, n.path = r, t._um_ssrc = u, t._um_sts = a;
        }

        return e.push(t), O().v("share: %o", n), n;
      },
      setShareSource: function (n) {
        i = n;
      },
      clear: function () {
        e.length = 0;
      },
      get: function () {
        return e;
      }
    };
  }

  var t = null,
      e = [],
      i = "";
  return function () {
    return t || (t = new n()), t;
  };
}(),
    tn = "ekvs",
    en = 1e4,
    rn = 1,
    on = function () {
  function n() {
    if (c.length) {
      var n = L().get(tn);
      e(n) + c.length <= en && (n = t(n, c), L().set(tn, n));
    }
  }

  function t(n, t) {
    var e = (n = n || {})[o];
    return Array.isArray(e) && e.length ? n[o] = e.concat(t) : n[o] = [].concat(t), n;
  }

  function e(n) {
    var t = 0;

    for (var e in n) Array.isArray(n[e]) && (t += n[e].length);

    return t;
  }

  function i() {
    return {
      addEvent: function (t) {
        o ? (c.unshift(t), c.length > rn && (n(o), c.length = 0)) : (O().w("session id is null: ", o), s.unshift(t));
      },
      setSessionId: function (n) {
        if (o = n, O().v("setSessionId: ", o), Array.isArray(s) && s.length && o) {
          for (var t = 0; t < s.length; t++) this.addEvent(s[t]);

          s.length = 0;
        }
      },
      getEkvs: function () {
        var n = L().get(tn);
        return c && c.length && (n = t(n, c)), n;
      },
      clear: function () {
        L().remove(tn), c.length = 0;
      }
    };
  }

  var r,
      o,
      c = [],
      s = [];
  return function () {
    return r || (r = i()), r;
  };
}(),
    cn = "2g",
    sn = "3g",
    un = "4g",
    an = "none",
    fn = " ",
    ln = ["access", "access_subtype"],
    dn = function () {
  function n() {
    function n(n) {
      C.getSystemInfo(function (i) {
        C.getNetworkInfo(function (o) {
          var c = o.type || o.networkType;
          c === an && (c = "unknown");
          var s = L().get(D.IMPRINT);
          s && (r.imprint = s), t(i, c), e(i), n && n();
        });
      });
    }

    function t(n, t, e) {
      if (r.userInfo = e, r.device_type = "Phone", r.sdk_version = D.IMPL_VERSION, r.appkey = k().appKey(), n) {
        var i,
            o,
            c,
            s = n.model || "",
            u = (n.product, n.platform || ""),
            a = n.brand || "",
            f = a.toLowerCase();
        r.platform_sdk_version = n.SDKVersion, r.platform_version = n.version, c = (i = Math.round(n.screenWidth * n.pixelRatio)) > (o = Math.round(n.screenHeight * n.pixelRatio)) ? i + "*" + o : o + "*" + i, r.os = u, r.font_size_setting = n.fontSizeSetting, r.device_model = s.toLowerCase().indexOf(f) > -1 ? s : f + fn + s, r.device_brand = a, r.device_manufacturer = f, r.device_manuid = s.toLowerCase().indexOf(f) > -1 ? s : f + fn + s, r.device_name = s.toLowerCase().indexOf(f) > -1 ? s : f + fn + s, r.os_version = n.system, r.resolution = c, r.language = n.language;
      }

      switch (t) {
        case un:
          r.access_subtype = "LTE", r.access = "4G";
          break;

        case sn:
          r.access_subtype = "CDMA", r.access = "3G";
          break;

        case cn:
          r.access_subtype = "GRPS", r.access = "2G";
          break;

        default:
          r.access = t, delete r.access_subtype;
      }
    }

    function e(n) {
      var t = [];
      n && (t.push({
        name: "系统名",
        value: n.platform
      }), t.push({
        name: "支付宝版本号",
        value: n.version
      })), t.push({
        name: "设备型号",
        value: r.device_model
      }), t.push({
        name: "设备生产商",
        value: r.device_brand
      }), t.push({
        name: "os版本号",
        value: r.os_version
      }), t.push({
        name: "网络类型",
        value: r.access
      }), t.push({
        name: "运营商",
        value: r.access_subtype
      }), t.push({
        name: "分辨率",
        value: r.resolution
      }), t.push({
        name: "screenWidth",
        value: n.screenWidth
      }), t.push({
        name: "screenHeight",
        value: n.screenHeight
      }), t.push({
        name: "pixelRatio",
        value: n.pixelRatio
      });

      for (var e = "", i = 0; i < t.length; i++) {
        var o = t[i];
        e += o.name + ": " + o.value + "; ";
      }

      O().v("调试辅助信息: ", e);
    }

    var i = !1,
        r = {};
    return r.sdk_type = "wxmp", r.platform = "wx", {
      init: function () {
        n(function () {
          i = !0;
        });
      },
      isLoaded: function () {
        return i;
      },
      get: function () {
        return r;
      },
      getSDKType: function () {
        return r.sdk_type;
      },
      getPlatform: function () {
        return r.platform;
      },
      getRealtimeFields: function () {
        var n = {};
        return ln.forEach(function (t) {
          n[t] = r[t];
        }), n;
      },
      setIdTracking: function (n) {
        this.setItem("id_tracking", n);
      },
      setIdType: function (n) {
        this.setItem("id_type", n);
      },
      setItem: function (n, t) {
        r[n] = t;
      },
      getItem: function (n) {
        return r[n];
      },
      updateExtraInfo: function () {
        C.getDeviceInfo(function (n) {
          r.device_info = n || "";
        });
      }
    };
  }

  var t = null;
  return {
    instance: function () {
      return t || (t = n()), t;
    }
  };
}(),
    pn = {
  HALF_SESSION: "half_session",
  CLOSE_SESSION: "close_session",
  EKV: "ekv"
},
    hn = function () {
  function n() {
    return {
      resume: function (n) {
        var t = !1;
        c || (c = L().get(D.CURRENT_SESSION));
        var i = new Date();
        return o = i.getTime(), !c || !c.end_time || o - c.end_time > D.SESSION_INTERVAL ? (t = !0, e(n), O().v("开始新的session(%s): ", c.id, c)) : O().v("延续上一次session(%s): %s ", c.id, i.toLocaleTimeString(), c), t;
      },
      pause: function () {
        i();
      },
      getCurrentSessionId: function () {
        return (c || {}).id;
      },
      getCurrentSession: function () {
        return c;
      },
      cloneCurrentSession: function () {
        return W.clone(c);
      }
    };
  }

  function t(n) {
    var t = {};

    for (var e in n) 0 === e.indexOf("_um_") && (t[e] = n[e]);

    return t;
  }

  function e(n) {
    try {
      var e = (c || {}).options || {},
          i = Object.assign({}, t(n.query));
      i.path = n.path || e.path, i.scene = n.scene ? dn.instance().getPlatform() + "_" + n.scene : e.scene, O().v("session options: ", i);
      var r = i[D.UM_SSRC];
      r && nn().setShareSource(r);
      var o = Date.now();
      c = {
        id: W.getRandomStr(10) + o,
        start_time: o,
        options: i
      };
    } catch (n) {
      O().e("生成新session失败: ", n);
    }
  }

  function i() {
    if (c) {
      var n = new Date();
      c.end_time = n.getTime(), "number" != typeof c.duration && (c.duration = 0), c.duration = c.end_time - o, L().set(D.CURRENT_SESSION, c), O().v("退出会话(%s): %s ", c.id, n.toLocaleTimeString(), c);
    }
  }

  var r = null,
      o = null,
      c = null;
  return function () {
    return r || (r = n()), r;
  };
}(),
    gn = {
  sessions: "sn",
  ekvs: "e"
},
    vn = {
  sdk_type: "sdt",
  access: "ac",
  access_subtype: "acs",
  device_model: "dm",
  language: "lang",
  device_type: "dt",
  device_manufacturer: "dmf",
  device_name: "dn",
  platform_version: "pv",
  id_type: "it",
  font_size_setting: "fss",
  os_version: "ov",
  device_manuid: "did",
  platform_sdk_version: "psv",
  device_brand: "db",
  appkey: "ak",
  _id: "id",
  id_tracking: "itr",
  imprint: "imp",
  sdk_version: "sv",
  resolution: "rl"
},
    _n = {
  uuid: "ud",
  unionid: "und",
  openid: "od",
  alipay_id: "ad",
  device_id: "dd",
  userid: "puid"
},
    yn = function () {
  function n(t, e) {
    if (dn.instance().isLoaded()) {
      var i = r(t),
          o = dn.instance().getRealtimeFields();
      i.header = Object.assign({}, i.header, o), a.enqueue(i), "function" == typeof e && e();
    } else setTimeout(function () {
      n(t, e);
    }, 100);
  }

  function t(n) {
    var i = a.front();
    i ? d(i, function () {
      a.dequeue(), t(n);
    }, function () {
      var e = a.dequeue();
      e && u.push(e), t(n);
    }) : (e(), n());
  }

  function e() {
    u.forEach(function (n) {
      a.enqueue(n);
    }), u.length = 0;
  }

  function i(n) {
    Z().getId() ? s ? O().i("队列正在发送中") : C.checkNetworkAvailable(function (e) {
      !1 !== e ? (s = !0, t(function () {
        s = !1, "function" == typeof n && n();
      })) : "function" == typeof n && n();
    }) : (O().i("获取id标识失败，暂缓发送"), "function" == typeof n && n());
  }

  function o() {
    this.send = function (n, t) {
      n ? this.add(n, function () {
        i(t);
      }) : i(t);
    }, this.add = function (t, e) {
      n(t, e);
    }, this.load = function () {
      var n = L().get(D.REQUESTS);
      n && n.length && n.forEach(function (n) {
        a.enqueue(n);
      }), L().remove(D.REQUESTS);
    }, this.save = function () {
      L().set(D.REQUESTS, W.clone(a.items())), a.clear();
    };
  }

  var c = null,
      s = !1,
      u = [],
      a = new g(50);
  return function () {
    return c || (c = new o()), c;
  };
}(),
    En = [];

_.prototype = {
  createMethod: function (n, t, e) {
    try {
      n[t] = e ? function () {
        return e[t].apply(e, arguments);
      } : function () {
        En.push([t, [].slice.call(arguments)]);
      };
    } catch (n) {
      O().v("create method errror: ", n);
    }
  },
  installApi: function (n, t) {
    try {
      var e,
          i,
          r = ["resume", "pause", "trackEvent", "trackPageStart", "trackPageEnd", "trackShare", "setOpenid", "setUnionid", "setUserid"];

      for (e = 0, i = r.length; e < i; e++) this.createMethod(n, r[e], t);

      if (t) for (e = 0, i = En.length; e < i; e++) {
        var o = En[e];

        try {
          t[o[0]].apply(t, o[1]);
        } catch (n) {
          O().v("impl[v[0]].apply error: ", o[0], n);
        }
      }
    } catch (n) {
      O().v("install api errror: ", n);
    }
  }
};

try {
  var Sn = App;

  App = function (n) {
    y(n, "onLaunch", function () {
      E(n.umengConfig);
    }), y(n, "onShow", S), y(n, "onHide", m), Sn(n);
  };
} catch (n) {
  O().w("App重写异常");
}

try {
  var mn = Page;

  Page = function (n) {
    if (y(n, "onShow", I), y(n, "onHide", A), y(n, "onUnload", A), n.onShareAppMessage) {
      var t = n.onShareAppMessage;

      n.onShareAppMessage = function (n) {
        var e = t.call(this, n);
        return Nn.trackShare.call(this, e);
      };
    }

    mn(n);
  };
} catch (n) {
  O().w("Page重写异常");
}

try {
  var In = Component;

  Component = function (n) {
    try {
      n.methods = n.methods || {};
      var t = n.methods;

      if (y(t, "onShow", I), y(t, "onHide", A), y(t, "onUnload", A), t.onShareAppMessage) {
        var e = t.onShareAppMessage;

        t.onShareAppMessage = function (n) {
          var t = e.call(this, n);
          return Nn.trackShare.call(this, t);
        };
      }

      In(n);
    } catch (t) {
      In(n);
    }
  };
} catch (n) {
  O().w("Component重写异常");
}

var An = new _(),
    Nn = {
  _inited: !1,
  init: function (n) {
    if (this._inited) O().v("已经实例过，请避免重复初始化");else if (n) {
      if (n.appKey) {
        k().set(n), O().setDebug(n.debug), this._inited = !0;
        var t = this;
        k().useOpenid() && O().tip_w("您选择了使用openid进行统计，请确保使用setOpenid回传openid或通过设置autoGetOpenid为true，并在友盟后台设置secret由友盟帮您获取"), function (n) {
          try {
            var t = new v();
            O().v("成功创建Lib对象"), t.init(function () {
              O().v("Lib对象初始化成功"), An.installApi(n, t), O().v("安装Lib接口成功");
            });
          } catch (n) {
            O().w("创建Lib对象异常: " + n);
          }
        }(t);
      } else O().err("请确保传入正确的appkey");
    } else O().err("请通过在App内添加umengConfig设置相关信息！");
  }
};

try {
  An.installApi(Nn, null), O().v("安装临时接口成功"), uni.uma = Nn;
} catch (n) {
  O().w("uma赋值异常: ", n);
}

module.exports = Nn;